import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

public class WaitDemo6 {
    public static void main(String[] args) {
        Object lock=new Object();
        Object lock2=new Object();
        new Thread(()->{
            System.out.println("线程1:开始执行");
            synchronized (lock){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程1：执行完成");
            }
        },"无参wait方法").start();

        new Thread(()->{
            synchronized (lock){
                System.out.println("线程2:开始执行"+ LocalDateTime.now());
                try {
                    lock.wait(60*60*60*1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程2：执行完成"+LocalDateTime.now());
            }
        },"有参wait方法").start();

        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lock){
                System.out.println("唤醒线程2");
                lock.notifyAll();
            }
        }).start();
    }
}
